﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Data;
using XXVIII.Entity;
using System.Text.RegularExpressions;

namespace XXVIII.Api.Models
{

    /// <summary>
    /// 附加类
    /// </summary>
    public class Pickout
    {
        private static object objLock = new object();

        /// <summary>
        /// 构造
        /// </summary>
        public Pickout() { }

        /// <summary>
        /// 调整分页默认值
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static DBPageBase SetPage(dynamic entity)
        {
            DBPageBase pager = new DBPageBase();
            if (entity != null)
            {
                pager.PageIndex = entity.PageIndex == 0 ? 1 : entity.PageIndex;
                pager.PageSize = entity.PageSize == 0 ? 20 : entity.PageSize;
            }
            return pager;
        }

        /// <summary>
        /// 验证表列名合法性 字母 数字 下划线
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static bool CheckTableColumnName(string input)
        {
            string regex = @"^[a-zA-Z_][A-Za-z0-9_]*$";
            if (!string.IsNullOrEmpty(input) && System.Text.RegularExpressions.Regex.IsMatch(input, regex))
            {
                return true;
            }
            return false;
        }

    }
}